/*
 * @Author: 0x9DEFA478
 * @Date: 2023-02-26 20:25:12
 * @LastEditTime: 2023-03-13 21:14:18
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * QQ:2652450237
 * ============================================================================================================================================
 * 
 * 
 * 
 *                                                                                               ************      ****************************
 *                                                                                             ************      ****************************  
 *                                                                                           ************      ****************************    
 *                                                                                         ************      ****************************      
 *                                                                                       ************      ************                        
 *                                                                                     ************      ************                          
 *                                                                                   ************      ************                            
 *                                                                                 ************      ************                              
 *                                                                               ************      ************                                
 *                                                                             ************      ************                                  
 *                                                                           ************      ************                                    
 *                                                                         ************      ************                                      
 *                                                                       ************      ************                                        
 *                                                                     ************      ************                                          
 *                                                                   ************      ************                                            
 *                                                                 ************      ************                                              
 *                                                               ************      ************                                                
 *                                                             ************      ************                                                  
 *                                                           ************      ************                                                    
 *                                                         ************      ************                                                      
 *                                                       ************      ************                                                        
 *                                                     ************      ************                                                          
 *                                                   ************      ************                                                            
 *                                                 ************      ************                                                              
 *                                               ************      ************                                                                
 *                                             ************      ************                                                                  
 *                                           ************      ************                                                                    
 *                                         ************      ************                                                                      
 *                                       ************      ************                                                                        
 *                                     ************      ************                                                                          
 *                                   ************      ************                                                                            
 *                                 ************      ************                                                                              
 *                               ************      ************                                                                                
 *                             ************      ************                                                                                  
 *                           ************      ************                                                                                    
 *                         ************      ************                                                                                      
 *       ****************************      ************                                                                                        
 *     ****************************      ************                                                                                          
 *   ****************************      ************                                                                                            
 * ****************************      ************                                                                                              
 * 
 * 
 * 
 * ============================================================================================================================================
 * 
 */
#ifndef __PinAssignment_H_
#define __PinAssignment_H_
#include <QObject>
#include <QString>
#include <QColor>
#include <QList>




class PinAssignment:public QObject{
    Q_OBJECT
  public:

    enum class ColorIndex:int{
      NC=0,
      GND=1,
      Power=2,
      Sys=3,
      
      IO_NoFunction=4,
      IO_Selectable=5,
      IO_Function=6,
      IO_Conflict=7,
      IO_FunctionConflict=8,

      Max=9
    };

    class PinStatus{

      public:
        PinStatus(QColor bgColor,int index){
          this->bgColor=bgColor;
          this->index=index;
        }
        PinStatus(const PinStatus& s){
          this->bgColor=s.bgColor;
          this->index=s.index;
        }
        ~PinStatus(){}

        int Index(){return index;}

        QColor BgColor(){return bgColor;}

      private:
        QColor bgColor;
        int index;
    };

    class PinInfo{
      private:
        void CopyToThis(const PinInfo& pinInfo){
          this->index=pinInfo.index;
          this->name=pinInfo.name;
          this->functions=pinInfo.functions;
        }
        void CopyToThis(int index,QString& name,QStringList& functions){
          this->index=index;
          this->name=name;
          this->functions=functions;
        }
      public:
        PinInfo(const PinInfo& pinInfo){
          CopyToThis(pinInfo);
        }
        PinInfo(const PinInfo&& pinInfo){
          CopyToThis(pinInfo);
        }
        PinInfo(int index,QString&& name,QStringList functions=QStringList()){
          CopyToThis(index,name,functions);
        };
        PinInfo(int index,QString& name,QStringList functions=QStringList()){
          CopyToThis(index,name,functions);
        };
        PinInfo(int index,const char* name,QStringList functions=QStringList()){
          this->index=index;
          this->name=name;
          this->functions=functions;
        }
        ~PinInfo(){}

        PinInfo& operator=(const PinInfo& pinInfo){
          CopyToThis(pinInfo);
          return this[0];
        };

        PinInfo& operator=(const PinInfo&& pinInfo){
          CopyToThis(pinInfo);
          return this[0];
        };

        int Index(){return index;}

        const QString& Name()const{
          return name;
        }
        QString Name(){
          return name;
        }

        const QStringList& Functions()const{
          return functions;
        }
        QStringList Functions(){
          return functions;
        }

      private:
        int index;
        QString name;
        QStringList functions;
    };

    PinAssignment(QObject* parent=nullptr);
    ~PinAssignment();

    void GetFunctionList(QStringList& FunctionList);
    void GetPinList(QList<PinInfo>& PinList);
    void AllPinUpdate();
    void SetColor(ColorIndex index,int r,int g,int b);

    void GetPackageSize(int* W,int* H){W[0]=Width;H[0]=Height;}
    void HighLightFunction(int GlobalFunctionIndex,bool IsHighLight);
    void FunctionSelect(int PinIndex,int FunctionIndex);

    void SaveFile(QString& Path);
    void LoadFile(const QString& Path);
    void LoadFile(const QString&& Path){LoadFile(Path);}

    void pPinFunctionChange(int X,int Y,int Index);

  signals:
    void PinFunctionChange(int PinIndex,PinAssignment::PinStatus Status);

  private slots:



  private:
    QColor Palette[(int)ColorIndex::Max];
    void* PinMatrix;
    int Width;
    int Height;
    void* PinList;
    int PinListSize;
    void* FunList;
    int GlobalFunctionIndex;
    QList<int> HighLightPins;
    unsigned char* HPAFile;
    qint64 HPAFile_Size;

    
    void pinAssignment();
    void LoadSPA(const QString& Path);
    void LoadHPA(const QString& Path);



};




#endif //__PinAssignment_H_
